

package edu.gatech.cs2340.mule.tests;
import static org.junit.Assert.*;

import java.awt.Color;
import java.awt.Point;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import edu.gatech.cs2340.mule.model.Mule;
import edu.gatech.cs2340.mule.model.Player;
import edu.gatech.cs2340.mule.model.Map;
import edu.gatech.cs2340.mule.model.Race;
import edu.gatech.cs2340.mule.model.TerrainTile;

/**
 * CalculateProduction.java
 * This JUnit class tests the calculate production method.
 * 
 * @author J.R. O'Donnell
 */

public class CalculateProduction {
	
	public Player dummyPlayer;
	public Map dummyMap;

	@Before
	public void setUp() throws Exception {
		// Create test player and test map
		dummyPlayer = new Player(Color.RED, "2PAC", new Race("Buzzite")); // Arbitrary
		dummyMap = new Map(); // Default Map
	}
	
	// No owned land
	@Test
	public void testNoLand(){
		dummyPlayer.calculateProduction(dummyMap);
		Assert.assertEquals("Food amount is incorrect.",0, dummyPlayer.getFoodAmount());
		Assert.assertEquals("Smithore amount is incorrect",0, dummyPlayer.getSmithOreAmount());
		Assert.assertEquals("Energy amount is incorrect",0, dummyPlayer.getEnergyAmount());
	}
	
	// No MULEs
	@Test
	public void testNoMULEs(){
		// Give the player land
		dummyPlayer.addOwnedLand(new Point(0,0)); // Plains Tile
		//dummyPlayer.addOwnedLand(new Point(0,1)); // Plains Tile
		//dummyPlayer.addOwnedLand(new Point(0,2)); // Mountain Tile Type 3
		dummyPlayer.setEnergyAmount(1);
		int[] dummyProductionChange = dummyPlayer.calculateProduction(dummyMap);
		Assert.assertEquals("Food amount is incorrect.",0, dummyProductionChange[0]);
		Assert.assertEquals("Energy amount is incorrect",0, dummyProductionChange[1]);
		Assert.assertEquals("Smithore amount is incorrect",0, dummyProductionChange[2]);
	}
	
	// 1 owned land
	
	@Test
	public void testOneMULE() {
		// Give the player land
		dummyPlayer.addOwnedLand(new Point(0,0)); // Plains Tile
		// Give the land a mule
		dummyPlayer.setEnergyAmount(1);
		((TerrainTile)dummyMap.getMapTileAt(new Point(0,0))).addMule(new Mule(Mule.FOOD_TYPE));
		int[] dummyProductionChange = dummyPlayer.calculateProduction(dummyMap);
		Assert.assertEquals("Food amount is incorrect.",2, dummyProductionChange[0]);
		Assert.assertEquals("Energy amount is incorrect",0, dummyProductionChange[1]);
		Assert.assertEquals("Smithore amount is incorrect",0, dummyProductionChange[2]);
	}
	
	@Test
	public void testMoreThanOneMULE() {
		// Give the player land
		dummyPlayer.addOwnedLand(new Point(0,0)); // Plains Tile
		dummyPlayer.addOwnedLand(new Point(0,1)); // Plains Tile
		dummyPlayer.addOwnedLand(new Point(0,2)); // Mountain Type 3
		// Give the land a mule
		dummyPlayer.setEnergyAmount(2);
		((TerrainTile)dummyMap.getMapTileAt(new Point(0,0))).addMule(new Mule(Mule.FOOD_TYPE));
		((TerrainTile)dummyMap.getMapTileAt(new Point(0,1))).addMule(new Mule(Mule.FOOD_TYPE));
		int[] dummyProductionChange = dummyPlayer.calculateProduction(dummyMap);
		Assert.assertEquals("Food amount is incorrect.",4, dummyProductionChange[0]);
		Assert.assertEquals("Energy amount is incorrect",0, dummyProductionChange[1]);
		Assert.assertEquals("Smithore amount is incorrect",0, dummyProductionChange[2]);
	}
	
	@Test
	public void testAllMULEs() {
		// Give the player land
		dummyPlayer.addOwnedLand(new Point(0,0)); // Plains Tile
		dummyPlayer.addOwnedLand(new Point(0,1)); // Plains Tile
		dummyPlayer.addOwnedLand(new Point(0,2)); // Mountain Type 3
		// Give the land a mule
		dummyPlayer.setEnergyAmount(3);
		((TerrainTile)dummyMap.getMapTileAt(new Point(0,0))).addMule(new Mule(Mule.FOOD_TYPE));
		((TerrainTile)dummyMap.getMapTileAt(new Point(0,1))).addMule(new Mule(Mule.FOOD_TYPE));
		((TerrainTile)dummyMap.getMapTileAt(new Point(0,2))).addMule(new Mule(Mule.SMITHORE_TYPE));
		int[] dummyProductionChange = dummyPlayer.calculateProduction(dummyMap);
		Assert.assertEquals("Food amount is incorrect.",4, dummyProductionChange[0]);
		Assert.assertEquals("Energy amount is incorrect",0, dummyProductionChange[1]);
		Assert.assertEquals("Smithore amount is incorrect",2, dummyProductionChange[2]);
	}
	
	@Test
	public void testNoEnergy() {
		// Give the player land
		dummyPlayer.addOwnedLand(new Point(0,0)); // Plains Tile
		// Give the land a mule
		dummyPlayer.setEnergyAmount(0);
		((TerrainTile)dummyMap.getMapTileAt(new Point(0,0))).addMule(new Mule(Mule.FOOD_TYPE));
		int[] dummyProductionChange = dummyPlayer.calculateProduction(dummyMap);
		Assert.assertEquals("Food amount is incorrect.",0, dummyProductionChange[0]);
		Assert.assertEquals("Energy amount is incorrect",0, dummyProductionChange[1]);
		Assert.assertEquals("Smithore amount is incorrect",0, dummyProductionChange[2]);
	}

}
